// pages/user/special/detail/detail.js
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: -1,
    richText:'',
    isJoinSpecial: false, 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let {id, type} = options;
    this.data.id = id;
    this.data.type = type - 1;
    if (type == 2) { // 已申请专场
      this.setData({isJoinSpecial: true})
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    token = getApp().globalData.token;
    this.getDetail();
  },

  getDetail() {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'special_activity/' + this.data.id,
      method: 'GET',
      data: {
        token: token,
        type: this.data.type
      },
      success: (res) => {
        let canSpecialPositions = [], errSpecialPositions = [];
        res.specialPositions.forEach(m => {
          if (m.checked == 1) {  // 已通过
            canSpecialPositions.push({
              name: m.name,
              num: m.num
            })
          }
          if (m.checked == 2) { // 未通过
            errSpecialPositions.push({
              name: m.name,
              num: m.num,
              reason: m.reason
            })
          }
        })
        this.setData({
          obj: res,
          canSpecialPositions,
          errSpecialPositions
        })
      }
    })
  },

  onToJoinPos() {
    wx.navigateTo({
      url: '../join/join?id=' + this.data.id,
    })
  },

  onMadePoster(){
    T.toast({ id: '#toast', text: '请前往黄埔E聘PC企业端进行操作' });
  },

  /**
   * 去新建职位
   */
  onCreatePosition() {
    let param = {
      specialId : this.data.id,
      origin: 'special'
    }

    wx.navigateTo({
      url: '/pages/position/fullTime/add/add?' + T.param(param),
    })
  }

})